# 查找最长相同子字符串
def CheckLongStr(STRB, STRM):
    if len(STRB) < len(STRM):
        STR3 = STRB
        STRB = STRM
        STRM = STR3
    for i in reversed(range(1,len(STRM))):
        for j in range(0, len(STRM)+1 - i):
            if STRM[j:j + i] in STRB:
                print(STRM[j:j + i])
                return
while True:
    try:
        CheckLongStr(input(), input())
    except:
        break